package utils

import (
	"golang.org/x/crypto/bcrypt"
	"k8s-admin/global"
)

func GenerateFromPassword(password []byte) (string, error) {
	b, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
	if err != nil {
		global.TPLogger.Error(err)

		return "", err
	}
	return string(b), nil
}

func CompareHashAndPassword(hashedPassword, password []byte) bool {
	if err := bcrypt.CompareHashAndPassword(hashedPassword, password); err != nil {
		global.TPLogger.Error(err)
		return false
	}
	return true
}
